/*
 * ctu.c
 * compress-that-url
 *
 * Lizens und so:
 * 	
 * 		Created by Nino A. on Mi, 01/08/09
 * 								<nino-a.froCensoftware@gmail.com> <-- Software issues
 *								<nino@annighoefer.net>            <-- love letters etc.
 * 
 * 		Donation-ware fro<C>en software 2009:
 * 								<http://froCensoftware.bplaced.net/>
 * 								<info.froCensoftware@gmail.com>
 * 
 * Geklaut wurde bei:
 * 		opentracker von Erdgeist <erdgeist@erdgeist.org>
 *    
 * Gelernt wurde von:
 *    Beej's guide to c
 *    Beej's guide to unix network programming
 *		Aaron Hillegass' Mac OS Programming
 *
 */

#include "ctu.h"

void mainloop( ) {
	for( ;; ) {
		if( ( connectfd = accept( listenfd, 0,0 ) ) < 0 )
			perror( "accept" );
	
		memset( &inbuf, 0, sizeof( inbuf ) );
		memset( &outbuf, 0, sizeof( outbuf ) );
		
		if( ( recv( connectfd, inbuf, 2048, 0 ) ) < 0 ) {
			perror( "recv" );
			close( connectfd );
			mainloop( );
		}
	
		parse( inbuf, outbuf );
		
		send( connectfd, outbuf, strlen( outbuf ), 0 );
	
		close( connectfd );
	}
	mainloop( );
}

int main( int argc, char * argv[ ] ) {		
	init_sock( &listenfd ); // initialize and listen on port LISTEN_PORT
	init_parser( );
	mainloop( );
	return 0;
}

